package com.mcode.blog.controller;

import com.mcode.blog.common.cache.Cache;
import com.mcode.blog.service.TagService;
import com.mcode.blog.vo.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("tags")
public class TagsController {

    @Resource
    private TagService tagService;

    /**
     * 热门标签
     * @return
     */
    @GetMapping("/hot")
    @Cache(expire = 5 * 60 * 1000, name = "hot_list_tag")
    public Result lists() {
        int limit = 6;
        return Result.success(tagService.hots(limit));
    }

    /**
     * 全部标签
     * @return
     */
    @GetMapping
    @Cache(expire = 5 * 60 * 1000, name = "list_all_tag")
    public Result findAll() {
        return Result.success(tagService.findAll());
    }

    /**
     * 标签列表
     * @return
     */
    @GetMapping("/detail")
    @Cache(expire = 5 * 60 * 1000, name = "list_detail_tag")
    public Result findAllDetail() {
        return Result.success(tagService.findAll());
    }


    /**
     * 标签详情
     * @param id id
     * @return
     */
    @GetMapping("/detail/{id}")
    @Cache(expire = 5 * 60 * 1000, name = "detail_tag")
    public Result detail(@PathVariable("id") Long id) {
        return Result.success(tagService.findDetailById(id));
    }

}
